package com.mission.schedule.adapter;

import java.util.List;

import com.mission.schedule.CommonDialog.ReminderEditDialog;
import com.mission.schedule.adapter.utils.CommonAdapter;
import com.mission.schedule.adapter.utils.ViewHolder;
import com.mission.schedule.bean.CYTXBean;
import com.mission.schedule.bean.ChangYongBean;
import com.mission.schedule.R;
import com.mission.schedule.cutimage.Log;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

public class DaoJiShiTiXingAdapter extends CommonAdapter<CYTXBean.DjsBean>{
	WindowManager windowManager;
	Handler handler;
	public DaoJiShiTiXingAdapter(Context context, List<CYTXBean.DjsBean> lDatas,
								 int layoutItemID, WindowManager windowManager, Handler handler) {
		super(context, lDatas, layoutItemID);

		this.windowManager = windowManager;
		this.handler = handler;
	}

	@Override
	public void getViewItem(ViewHolder holder, final CYTXBean.DjsBean item, final int position) {
		TextView title = holder.getView(R.id.title);
		TextView content_tv = holder.getView(R.id.content_tv);
		if (item.type == 2){
			if ((item.number / 0.5) % 2 == 1 ){
				title.setText(item.number+"");
			}else {
				title.setText((int)item.number+"");
			}
		}else {
			title.setText((int)item.number+"");
		}

		content_tv.setText(item.timetype+"");

		holder.getView(R.id.bianji).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				double num = 0;
				if (item.type == 1){
					num = item.number;
				}else if(item.type == 2){
					num = (item.number * 60);
				}
				ReminderEditDialog dialog = new ReminderEditDialog(context,R.style.dialog_translucent,windowManager,num);
				dialog.show();
				dialog.setCallBack(new ReminderEditDialog.CallBack() {
					@Override
					public void reminderEditTime(double number,int type) {
						Message message = new Message();
						message.what = 1;
						message.obj = number;
						message.arg1 = type;
						message.arg2 = position;
						handler.sendMessage(message);
					}
				});
			}
		});
	}
}
